package com.weixing.mall.provider.controller.admin;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.annotation.SysLog;
import com.weixing.mall.core.enums.OperateEnum;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.api.model.vo.AgentSettleVo;
import com.weixing.mall.provider.model.domain.AgentSettle;
import com.weixing.mall.provider.model.dto.AgentSettleEditDto;
import com.weixing.mall.provider.service.IAgentSettleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 代理商银行卡结算信息
 * @author  kfc
 * @since 1.0
 */
@Validated
@RestController
@RequestMapping("agent/settle")
public class AgentSettleController extends BaseController {

    @Autowired
    private IAgentSettleService agentSettleService;

    /**
     * 保存代理商银行卡结算信息
     * @param dto 参数
     * @return 结果
     */
    @PostMapping("")
    @NoRepeatSubmit
    @SysLog(type = OperateEnum.S, desp = "编辑代理商结算信息")
    public Result settle(AgentSettleEditDto dto) {
        return ResultUtil.success(agentSettleService.saveSettle(dto));
    }

    /**
     * 查询代理商银行卡结算信息
     * @param agentId 代理id
     * @return 结算信息
     */
    @GetMapping("/{agentId}")
    @NoRepeatSubmit
    public Result<AgentSettleVo> get(@PathVariable Long agentId) {
        AgentSettle agentSettle = agentSettleService.selectByAgentId(agentId);
        AgentSettleVo agentSettleVo = new AgentSettleVo();
        if (null != agentSettle) {
            BeanUtils.copyProperties(agentSettle, agentSettleVo);
        }
        return ResultUtil.success(agentSettleVo);
    }

}
